import React from 'react';
import { Button, Form, Select, Input, Row, Col, Modal, Message } from 'antd';
const FormItem = Form.Item;

let financeModal = React.createClass({

  handleCancel() {
    this.props.callBack();
    this.handleReset()
  },

  handleApply() {

    let form = this.props.form.getFieldsValue();
    let id  = this.props.record.id;
    let param = Object.assign({},{id: id}, form);
    // param.tenementId = this.props.tenementId;
    // param.rentContractId = this.props.rentContractId;
    // param.type = this.props.financeType;
    this.props.form.validateFieldsAndScroll((errors, values) => {
        if (!!errors) {
          console.log('Errors in form!!!');
          return;
        }
      Utils.sendAjax({
        url: '/loan/apply/again',
        data: JSON.stringify(param),
        callback: (result) => {
          if (result.code === '200') {
            this.handleCancel();
            this.props.loanList();
            Modal.success({
              title: '申请成功',
              content: '爱租派已经收到了您的申请，在三个工作日内会有业务人员联系您，请保持手机畅通~',
            });
          } else {
            Message.error(result.message, 10)
          }
        }
      });
    });
  },


  handleReset() {
    this.props.form.resetFields();
  },

  render () {

    const { getFieldProps } = this.props.form;

    const tipMap = {
      101: `房东大人，还在为收房资金发愁？为您准备【收房贷】贷款业务，只要是好地段、好房源，收房资金我们帮您出。`,
      102: `房东大人，装修储备资金不足，还在对着高性价比的装修品一筹莫展吗？为您准备【装修贷】贷款业务，装修验收完毕即可付款。`,
      103: `房东大人，持有多个公寓租约，临时需要资金周转怎么办？为您准备【租约贷】贷款业务，可以提前一次性把未来期限的房租都收到手。`,
    };

    return (
      <Modal title="申请融资" width={640}
             visible={this.props.visible}
             onCancel={this.handleCancel}
             footer="">
        <Form inline form={this.props.form}>
          <p>{tipMap[this.props.record.type]}</p>
          <Row gutter={24} className="form-group">
            <Col sm={12}>
              <FormItem
                label="申请金额">
                <Input ref="applyAmount" {...getFieldProps('applyAmount', {rules: [
                  {required: true, message: '申请金额不可为空'},
                  {validator: Utils.number},
                ]})}/>元
              </FormItem>
            </Col>
            <Col sm={12}>
              <FormItem
                label="申请期限">
                <Input {...getFieldProps('applyPeriod', {rules: [
                  {required: true, message: '申请期限不可为空'},
                  {validator: Utils.number},
                ]})}/>月
              </FormItem>
            </Col>
          </Row>
          <Row gutter={24} className="form-group">
            <Col sm={12}>
              <FormItem
                label="申请人">
                <Input {...getFieldProps('contactUser', {rules: [
                  {required: true, message: '申请人不可为空'}
                ]})}/>
              </FormItem>
            </Col>
            <Col sm={12}>
              <FormItem
                label="联系方式">
                <Input {...getFieldProps('contactPhone', {rules: [
                  {required: true, message: '联系方式不可为空'},
                  {validator: Utils.phone},
                ]})}/>
              </FormItem>
            </Col>
          </Row>
          <Row gutter={24} className="form-group">
            <Col sm={12}>
              <FormItem
                label="有效证件号">
                <Input {...getFieldProps('cardNo')}/>
              </FormItem>
            </Col>
            <Col sm={12}>
              <FormItem
                label="紧急联系人">
                <Input {...getFieldProps('urgencyContacts')}/>
              </FormItem>
            </Col>
          </Row>
          <Row gutter={24} className="form-group">
            <Col sm={12}>
              <FormItem
                label="联系方式">
                <Input {...getFieldProps('urgencyPhone', {rules: [
                  {validator: Utils.phone},
                ]})}/>
              </FormItem>
            </Col>
            <Col sm={12}>
              <FormItem
                label="收款方户名">
                <Input {...getFieldProps('payeeName')}/>
              </FormItem>
            </Col>
          </Row>
          <Row gutter={24} className="form-group">
            <Col sm={12}>
              <FormItem
                label="开户行">
                <Input {...getFieldProps('bankName')}/>
              </FormItem>
            </Col>
            <Col sm={12}>
              <FormItem
                label="收款账号">
                <Input {...getFieldProps('payeeAccount')}/>
              </FormItem>
            </Col>
          </Row>
           <Row gutter={24} className="form-group">
            <Col sm={24}>
              <FormItem
                label="借款用途">
                <Input type="textarea" {...getFieldProps('mark')} style={{width: 400}}/>
              </FormItem>
            </Col>
          </Row>
          <Row gutter={24}>
            <Col offset={10} sm={14}>
              <FormItem
                label="">
                <Button type="primary" onClick={this.handleApply}>立即申请</Button>
              </FormItem>
            </Col>
          </Row>
        </Form>
      </Modal>
    );
  }
});

financeModal = Form.create()(financeModal);
export default financeModal